import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    
    path: '/Home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: "/user",
        name: "user",
        component: () => import('../views/user/index.vue'),
        children: [
          {
            path: "adduser",
            name: "adduser",
            component: () => import('../views/user/adduser.vue')
          },
          {
            path: "albnm_user",
            name: "albnm_user",
            component: () => import('../views/user/albnm_user.vue')
          },
          {
            path: "userlist",
            name: "userlist",
            component: () => import('../views/user/userlist.vue')
          },
        ]
      },
      {
        path: "/order",
        name: "order",
        component: () => import('../views/order/index.vue'),
        children: [
          {
            path: "order_ment",
            name: "order_ment",
            component: () => import('../views/order/order_ment.vue')
          },
          {
            path: "invoice_order",
            name: "invoice_order",
            component: () => import('../views/order/invoice_order.vue')
          },
          {
            path: "sale_order",
            name: "sale_order",
            component: () => import('../views/order/sale_order.vue')
          },
        ]
      },
      {
        path: "/dity",
        name: "dity",
        component: () => import('../views/dity/index.vue'),
        children: [
          {
            path: "ditylist",
            name: "ditylist",
            component: () => import('../views/dity/ditylist.vue')
          },
          {
            path: "cationlist",
            name: "cationlist",
            component: () => import('../views/dity/cationlist.vue')
          },
          {
            path: "moneydity",
            name: "moneydity",
            component: () => import('../views/dity/moneydity.vue')
          },
        ]
      }
    ]
  },
  {
    path: '/',
    name: 'login',
    component: () => import('../views/login.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 拦截权限
router.beforeEach((to, form, next) => {
  if (localStorage.getItem('token')) {
    next()
  } else {
    if (to.path == '/') {
      next()
    } else {
      next('/')
    }
  }
})

export default router
